package com.augurit.wf.jbpmex.cmd;


import org.jbpm.api.cmd.Environment;
import org.jbpm.pvm.internal.cmd.AbstractCommand;
import org.jbpm.pvm.internal.env.EnvironmentImpl;
import org.jbpm.pvm.internal.history.model.HistoryTaskImpl;
import org.jbpm.pvm.internal.session.DbSession;
import org.jbpm.pvm.internal.task.TaskImpl;

import com.augurit.wf.client.summary.service.IWfTaskSummaryService;

public class DelSubTaskCmd extends AbstractCommand<Void>{
	private static final long serialVersionUID = -5996415196851997153L;
	
	
	protected String taskId;
	
	public DelSubTaskCmd(String taskId){
		this.taskId = taskId;
	}
	
	public Void execute(Environment environment) throws Exception {
		Long taskDbid = Long.parseLong(taskId);
		
		DbSession dbSession  = environment.get(DbSession.class);
		TaskImpl subTask = dbSession.get(TaskImpl.class,taskDbid);
		
		//删除summary
//		IWfTaskSummaryService wfTaskSummaryService = EnvironmentImpl.getFromCurrent(IWfTaskSummaryService.class);
//	    wfTaskSummaryService.deleteSummaryTask(taskDbid);
	    
	    //查询historyTask
	    HistoryTaskImpl hisTaskImpl = dbSession.get(HistoryTaskImpl.class, taskDbid);
	    
	    //删除hisTask
	    dbSession.delete(hisTaskImpl);
	    
	    //删除自己
	    dbSession.delete(subTask);
		
		return null;
	}
}
